package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.BankListAdapter;
import com.jt.tenant.adapter.SpecialSaleListAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetBankList;
import com.jt.tenant.conn.GetSpecialSaleList;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

public class BankListActivity extends JTActivity implements OnClickListener {

    private TextView title;

    private ListView listView;

    private ImageView iv_bank_list;

    private List<GetBankList.BankList> mList = new ArrayList<>();

    private BankListAdapter mAdapter;

    private GetBankList getBankList = new GetBankList(new AsyCallBack<GetBankList.Info>(){
        @Override
        public void onSuccess(String toast, int type, GetBankList.Info info) throws Exception {

            super.onSuccess(toast, type,info);

            if(info.msg.equals("000")) {

                mList.clear();

                mList.addAll(info.bankLists);

                mAdapter.notifyDataSetChanged();

                JTApplication.UtilAsyncBitmap.get(info.logourl, iv_bank_list, R.mipmap.loading);

            }else {

                UtilToast.show(context,info.msg);

            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            super.onFail(toast, type);
        }

        @Override
        public void onEnd(String toast, int type) throws Exception {
            super.onEnd(toast, type);
            if(!toast.equals("")){

                UtilToast.show(BankListActivity.this, toast);

            }
        }
    });;

    private String ss_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_bank_list);

        initView();

    }

    @Override
    protected void onResume() {

        super.onResume();

        getBankList.execute(this);

    }

    private void initView() {

        (title = (TextView)findViewById(R.id.tv_title_name)).setText("选择银行");

        iv_bank_list = (ImageView)findViewById(R.id.iv_bank_list);

        listView = (ListView)findViewById(R.id.lv_bank);

        mAdapter = new BankListAdapter(this,mList);

        listView.setAdapter(mAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

                Intent intent = new Intent(context,ConductActivity.class);

                Bundle bundle = new Bundle();

                bundle.putString("id",mList.get(position).ID);

                intent.putExtras(bundle);

                startActivity(intent);

            }
        });

        getBankList.execute(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {


        }

    }


}
